var app = getApp();
Page({
  data: {
    show: false
  },
  onLoad: function(e) {
    console.log('web----',e)
    app.page.onLoad(this,e);
    app.bus.onLoad(this);
    var customerId = wx.getStorageSync('customerId');
    var url = decodeURIComponent(e.url);
    if (!customerId) {
      console.log("web-customerId")
      this.setData({show: true});
    } else {
      url += (/\?/.test(url)?'&':'?');
      url += ('customerId=' + customerId);
      url += ('&access_token=' + wx.getStorageSync('ACCESS_TOKEN'));
      url += ('&storeId=' + app.api.siteinfo.acid);
      url += ('&hosId=' + app.api.siteinfo.hosId);
      console.log(url);
      wx.navigateTo({
        url: '/pages/web/before/before?&url=' + encodeURIComponent(url) + '&title=' + e.title + '&img=' + e.img
      })
    }
  },
  getUserInfo: function(o) {
    console.log('web-getUserInfo')
    console.log('login-5')
    var n = this;
    "getUserInfo:ok" == o.detail.errMsg && app.core.login({
      success: function(e) {
        var t = e.code;
        n.unionLogin({
          code: t,
          user_info: o.detail.rawData,
          encrypted_data: o.detail.encryptedData,
          iv: o.detail.iv,
          signature: o.detail.signature
        });
      },
      fail: function(e) {}
    }) //: n.clearInfo()
  },
  unionLogin: function(e) {
    console.log('web-unionLogin')
    var o = this, n = app.page;
    app.core.showLoading({
      title: "正在登录",
      mask: !0
    }), app.request({
      url: app.api.passport.login,
      method: "POST",
      data: e,
      success: function(e) {
        if (0 == e.code) {
          o.setData({__user_info: e.data});
          app.setUser(e.data);
          app.core.setStorageSync(app.const.ACCESS_TOKEN, e.data.access_token);
          app.trigger.run(app.trigger.events.login);
          app.core.redirectTo({url: "/" + o.route + "?" + app.helper.objectToUrlParams(o.options,true)});
        } else app.login_complete = !1, app.core.showModal({
          title: "提示",
          content: e.msg,
          showCancel: !1
        });
      },
      complete: function() {
        app.core.hideLoading();
      }
    });
  },
});